package com.yanqu.road.server.cmd.activity.stronghold.wild;

import com.yanqu.road.entity.activity.UnionActivityConditionData;
import com.yanqu.road.pb.activity.StrongholdWarProto;
import com.yanqu.road.pb.crossunion.activity.CrossUnionActivityRankDataProto;
import com.yanqu.road.pb.rank.UnionActivityRankProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.strongholdwar.StrongholdActivityMgr;
import com.yanqu.road.server.manger.activity.strongholdwar.StrongholdActivityRankMgr;
import com.yanqu.road.server.manger.activity.strongholdwar.StrongholdWarMgr;
import com.yanqu.road.server.manger.cross.CrossDataMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;

import java.math.BigInteger;
import java.util.Collection;

@Cmd(code = GameProtocol.S_STRONGHOLD_UNION_RANK, desc = "")
public class StrongholdUnionRankCmd extends AbstractCommand {
    private int activityId;
    private int conditionType;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        StrongholdWarProto.StrongholdActivityUserRankListReqMsg req = StrongholdWarProto.StrongholdActivityUserRankListReqMsg.parseFrom(packet.getBytes());
        activityId = req.getActivityId();
        conditionType = req.getConditionType();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
       /* if (conditionType == StrongholdActivityMgr.CONDITION_TYPE_SILVER_UNION) {
            //如果是银两捐献 且不是捐献时间，直接读本地吧
            if (StrongholdActivityMgr.isAfterWildTime()) {
                sendLocalData(player);
                return;
            }
        }*/

        StrongholdWarProto.CrossStrongholdActivityUnionRankListReqMsg.Builder req = StrongholdWarProto.CrossStrongholdActivityUnionRankListReqMsg.newBuilder();
        req.setActivityId(activityId);
        req.setConditionType(conditionType);
        req.setUnionUid(player.getUserInfo().getUnionUid());
        player.sendUnionActivityGroupPacket(CrossProtocol.C_CROSS_STRONGHOLD_UNION_RANK, req, req.getActivityId());
    }

//    private void sendLocalData(GamePlayer player) {
//
//        String unionUid = player.getUserInfo().getUnionUid();
//        UnionActivityRankProto.UnionActivityRankListMsg tempList = CrossDataMgr.getCrossActivityUnionConditionTypeRankList(activityId, conditionType);
//        StrongholdWarProto.StrongholdActivityUnionRankListRespMsg.Builder msg = StrongholdWarProto.StrongholdActivityUnionRankListRespMsg.newBuilder();
//        msg.setMyRank(StrongholdWarMgr.getSilverRank(activityId, unionUid));
//        Collection<String> qualifyUnionList = StrongholdWarMgr.getQualifyUnionList(activityId, true);
//        BigInteger myUnionValue = BigInteger.ZERO;
//        UnionActivityRankProto.UnionActivityRankListMsg.Builder rankListMsg = UnionActivityRankProto.UnionActivityRankListMsg.newBuilder();
//        for (UnionActivityRankProto.UnionActivityRankTempMsg tempMsg : tempList.getRankListList()) {
//            if (qualifyUnionList.contains(tempMsg.getUnionUid())) {
//                rankListMsg.addRankList(tempMsg);
//            }
//            if (tempMsg.getUnionUid().equals(unionUid)) {
//                myUnionValue = new BigInteger(tempMsg.getValue());
//            }
//        }
//        msg.setValue(myUnionValue.toString());
//        msg.setRankList(rankListMsg);
//        player.sendChannelPacket(ClientProtocol.U_STRONGHOLD_UNION_RANK, msg);
//    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
